load("prdata.Rdata")

prdata$search<-"announces funding"
prdata$funding<-"funding"
prdata$grant<-"grant"
prdata$fund<-"fund"
prdata$other_sen<-"other senators"
prdata$other_rep<-"other representatives"
prdata$annual<-"annual"
prdata$avg<-"average"
prdata$last<-"last year"



prdata$grant_count<-NA

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_grant[i]<-grepl(prdata$grant[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_fund[i]<-grepl(prdata$fund[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_othersen[i]<-grepl(prdata$other_sen[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_otherrep[i]<-grepl(prdata$other_rep[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_annual[i]<-grepl(prdata$annual[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_avg[i]<-grepl(prdata$avg[i], prdata$TextsCol[i])
}

for(i in 1:length(prdata$TextsCol)){
  prdata$answer_last[i]<-grepl(prdata$last[i], prdata$TextsCol[i])
}


prdata$grant_num<-NA
prdata$compare_num<-NA
prdata$satisfy<-NA

for(i in 1:length(prdata$TextsCol)){
  if(prdata$answer_grant[i]==TRUE | prdata$answer_fund[i]==TRUE){
  prdata$grant_num[i]<-1
  }else{
    prdata$grant_num[i]<-0
  }
}

for(i in 1:length(prdata$TextsCol)){
  if(prdata$answer_othersen[i]==TRUE | prdata$answer_otherrep[i]==TRUE | prdata$answer_annual[i]==TRUE | prdata$answer_avg[i]==TRUE | prdata$answer_last[i]==TRUE){
    prdata$compare_num[i]<-1
  }else{
    prdata$compare_num[i]<-0
  }
}

for(i in 1:length(prdata$TextsCol)){
  if(prdata$compare_num[i]==1 & prdata$grant_num==1){
    prdata$satisfy[i]<-1
  }else{
    prdata$satisfy[i]<-0
  }
}

for(i in 1:length(prdata$TextsCol)){
  if(grepl(prdata$grant_count[i], prdata$TextsCol[i])==TRUE){
    prdata$grant_count==1
  } else if(grepl(prdata$grant_count[i], prdata$TextsCol[i])==FALSE) {
    prdata$grant_count==0
  } else if (NA){
    prdata$grant_count==0
  } else{
    prdata$grant_count==0
  }
}